package environment;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;

import util.Vector;

public class Ball
{
	private Vector position, velocity;
	private boolean isOwned;
	
	protected static double SIZE = 10;
	private static double MAX_SPEED = 10;
	
	public Ball(Vector position)
	{
		this.position = position;
		velocity = new Vector();
		isOwned = false;
	}
	
	public Ball(Vector position, Vector velocity)
	{
		this.position = position;
		this.velocity = velocity;
	}
	
	public void kick(Vector impulse)
	{
		velocity.add(impulse);
	}
	
	public void update()
	{
		// friction
		velocity.multiply(0.97);
		velocity.cutOff(0.05);
		velocity.limit(MAX_SPEED);
		position.add(velocity);
	}
	
	public Vector getVelocity()
	{
		return velocity.clone();
	}
	
	public void setVelocity(Vector newVeclocity)
	{
		this.velocity = newVeclocity;
	}
	
	public Vector getPosition()
	{
		return position;
	}
	
	public void setPosition(Vector position)
	{
		this.position = position;
	}
	
	public void draw(Graphics2D g2)
	{
		Ellipse2D.Double circle = new Ellipse2D.Double(position.getX() - SIZE/2,
								position.getY() - SIZE/2,
								SIZE,
								SIZE);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
	                        RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setColor(Color.BLACK);
		g2.fill(circle);
		g2.draw(circle);								
	}
}
